package com.sgb.kjwl.view.widget.transport;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.amap.api.maps.model.LatLng;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.DialogMapNavigationBinding;
import com.sgb.kjwl.model.entity.transport.common.AddressItem;
import com.sgb.kjwl.utils.MapNavigationUtils;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;
import com.swgk.core.util.MToast;

/**
 * @author: 杨畔
 * @date: 3/10/21 2:35 PM
 * @Description: 地图导航弹窗
 */
public class MapNavigationDialog extends BaseBottomDialog implements View.OnClickListener {
    private DialogMapNavigationBinding mBinding;
    //地区数据
    private AddressItem mLocation;

    public MapNavigationDialog(Context context) {
        super(context, null);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.dialog_map_navigation;
    }

    @Override
    protected void initView(DialogViewHolder holder, Bundle savedInstanceState) {
        mBinding = (DialogMapNavigationBinding) holder.getmBinding();
        initEvent();
    }

    private void initEvent() {
        mBinding.gaodeLayout.setOnClickListener(this);
        mBinding.baiduLayout.setOnClickListener(this);
        mBinding.tengxunLayout.setOnClickListener(this);
        mBinding.cancelView.setOnClickListener(this);
    }

    /**
     * 导航
     */
    public void navigation(AddressItem item) {
        if (item == null || isShowing()) return;
        mLocation = item;
        show();
    }

    @Override
    public void onClick(View v) {
        if (mLocation == null) {
            dismiss();
            return;
        }
        if (v == mBinding.gaodeLayout) {
            if (MapNavigationUtils.haveGaodeMap(context)) {
                MapNavigationUtils.openGaodeMap(context,
                        new LatLng(mLocation.getLatitude(), mLocation.getLongitude()),
                        mLocation.getAddressdetail());
            } else {
                MToast.showToast(context, "该手机没安装高德地图");
            }
        } else if (v == mBinding.baiduLayout) {
            if (MapNavigationUtils.haveBaiduMap(context)) {
                MapNavigationUtils.openBaiduMap(context,
                        new LatLng(mLocation.getLatitude(), mLocation.getLongitude()),
                        mLocation.getAddressdetail());
            } else {
                MToast.showToast(context, "该手机没安装百度地图");
            }

        } else if (v == mBinding.tengxunLayout) {
            if (MapNavigationUtils.haveTencentMap(context)) {
                MapNavigationUtils.openTentcentMap(context,
                        new LatLng(mLocation.getLatitude(), mLocation.getLongitude()),
                        mLocation.getAddressdetail());
            } else {
                MToast.showToast(context, "该手机没安装腾讯地图");
            }
        }
        dismiss();
    }
}
